import { PageRoutesTypeEnum } from 'pub-bbx-global/pageType/dist/enum/PageRoutesEnum';
import { openAccurateTab } from '@src/util/platform';
import platform from '@src/platform';

// 产品详情
export function openProductDetailTab(productId = '') {
  if (!productId.length) return;

  openAccurateTab({
    type: PageRoutesTypeEnum.PageProductView,
    key: productId,
    params: 'noHistory=1',
  });
}
// 跳转客户详情
export function openCustomerDetailTab(customerId = '') {
  if (!customerId.length) return;

  openAccurateTab({
    type: PageRoutesTypeEnum.PageCustomerView,
    key: customerId,
    params: 'noHistory=1',
  });
}

// 刷新tab
export function reloadTab() {
  let fromId = window.frameElement.getAttribute('fromid');
  platform.refreshTab(fromId);
}

// 项目列表页面
export function jumpPageProjectList() {
  let fromId = window.frameElement.getAttribute('id');

  openAccurateTab({
    type: PageRoutesTypeEnum.PageProjectList,
    closeNowPage: true,
    fromId,
  });
}
// 项目管理编辑
export function jumpProjectTypeEdit(row) {
  if (!row.id) return;

  let fromId = window.frameElement.getAttribute('id');

  openAccurateTab({
    type: PageRoutesTypeEnum.PageProjectManageEdit,
    key: row.id,
    closeNowPage: true,
    params: `templateId=${row.templateId}&id=${row.id}&action=edit`,
    fromId,
  });
}

// 项目管理复制
export function jumpProjectTypeCopy(row) {
  if (!row.id) return;

  let fromId = window.frameElement.getAttribute('id');

  openAccurateTab({
    type: PageRoutesTypeEnum.PageProjectManageCreate,
    key: row.id,
    closeNowPage: true,
    params: `templateId=${row.templateId}&id=${row.id}&action=copy`,
    fromId,
  });
}

// 项目管理详情
export function jumpProjectTypeDetail(row, isPersonnelTab = false) {
  // isPersonnelTab 项目详情页面是否选中人员卡片
  if (!row.id) return;

  let fromId = window.frameElement.getAttribute('id');

  openAccurateTab({
    type: PageRoutesTypeEnum.PageProjectManageView,
    key: row.id,
    params: `templateId=${row.templateId}&id=${row.id}&isPersonnelTab=${isPersonnelTab}`,
    closeNowPage: true,
    fromId,
  });
}